package com.cloud.model.system;


import com.cloud.base.BaseEntity;
import com.cloud.model.Class;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * A SysRole.
 */
@Entity
@Table(name = "sys_role")
@EntityListeners(AuditingEntityListener.class)
public class SysRole extends BaseEntity {

    @Column(name = "role_name")
    @NotBlank(message = "角色名不能为空")
    private String roleName;

    @Column(name = "role_description")
    private String roleDescription;

    @ManyToMany(targetEntity=SysResource.class,fetch = FetchType.LAZY,cascade={CascadeType.PERSIST,CascadeType.MERGE})
    @JoinTable(name="sys_role_resource",
            joinColumns={@JoinColumn(name="role_Id")},
            inverseJoinColumns={@JoinColumn(name="resource_Id")})
    @JsonIgnore
    private Set<SysResource> sysresources = new HashSet<SysResource>();
    @ManyToMany(targetEntity=Class.class,cascade={CascadeType.PERSIST,CascadeType.MERGE})
    @JoinTable(name="role_class",
            joinColumns={@JoinColumn(name="role_Id")},
            inverseJoinColumns={@JoinColumn(name="class_Id")})
    private Set<Class> classSet=new HashSet<>();
    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getRoleDescription() {
        return roleDescription;
    }

    public void setRoleDescription(String roleDescription) {
        this.roleDescription = roleDescription;
    }

    public Set<SysResource> getSysresources() {
        return sysresources;
    }

    public void setSysresources(Set<SysResource> sysresources) {
        this.sysresources = sysresources;
    }

    public Set<Class> getClassSet() {
        return classSet;
    }

    public void setClassSet(Set<Class> classSet) {
        this.classSet = classSet;
    }
}
